const app = getApp();
Page({

    data: {
        data: {
          name: '',
          sex: 1,
          birthday: '',
          height: '',
          weight: '',
          mobile: '',
        },
        info: {

        },
      
        minDate: new Date(1900, 10, 1).getTime(),
        maxDate: new Date().getTime(),
        currentDate: new Date().getTime(),
        show: false
    },
  onLoad: function (options) {
    let str = options.info;
    if(!str) {
      wx.navigateBack({
        delta: 1,
      })
      return;
    }
    let info = JSON.parse(str);
    this.setData({
      info: info
    })
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          height: ((res.windowHeight * 750) / res.windowWidth) - 110
        })
      }
    });

  },
  changeName(e) {
    this.setData({
      'data.name': e.detail.value
    })
  },
  changeBirthday(e) {
    this.setData({
      'data.birthday': e.detail.value
    })
  },
  changeSex(e) {
    let type = e.currentTarget.dataset.type;
    this.setData({
      'data.sex': type
    })
  },
  changeHeight(e) {
    this.setData({
      'data.height': e.detail.value
    })
  },
  changeWeight(e) {
    this.setData({
      'data.weight': e.detail.value
    })
  },
  changeMobile(e) {
    this.setData({
      'data.mobile': e.detail.value
    })
  },
  choosedate(e) {
    this.setData({
      show: true
    })
  },
  cancel() {
    this.setData({
      show: false
    })
  },
  confirm(e) {
    this.setData({
      show: false
    })
  },
  onInput(event) {
    this.setData({
      'data.birthday': app.util.timeformat(event.detail, 'y-m-d')
    })
    this.setData({
      currentDate: event.detail
    });
  },
  getInfo() {
    app.http.$ajax({
      url: 'v1.'
    })
  },
  pay() {
      app.http.$ajax({
        url: 'v1.evaluation/add',
        data: {
          ...this.data.data,
          evalutation_id: this.data.info.id
        },
        loading: '正在提交订单...'
      }, {
          success: (res) => {
            let payData = JSON.parse(res.data);
            wx.requestPayment({
              ...payData,
              'success': function (res) {
                app.success('支付成功', function () {
                  //刷新当前页面
                  wx:wx.navigateTo({
                    url: '/pages/my-evaluation/my-evaluation',
                  })
                })
              },
              'fail': function (res) {
                app.error('支付失败')
              }
            })
          },
          fail: (res) => {

          }
      })
  }
})